<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <div th:include="common/common_libs :: commoncss(gis)" th:remove="tag"/>
</head>

<body>

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbarCollapse"
                    aria-expanded="false">
                <span class="sr-only">导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="">Logo</a>
        </div>
        <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="nav navbar-nav navbar-right" id="nav">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="iconfont icon-guanliyuan"></i>
                        <span th:text="${session.userInfo.userName}"></span><span
                                class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">修改密码</a></li>
                        <li><a href="/logout"><i class="iconfont icon-tuichu"></i> 退出</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="iconfont icon-baobei"></i></a>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:saveTheme('default')" class="text-center">默认主题</a>
                        </li>
                        <li><a href="javascript:saveTheme('dark')" class="text-center">科技主题</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="gis-layout-right">
    <div layout:fragment="content" th:remove="tag"></div>
</div>

<footer class="gis-layout-footer bg-primary">
    <div th:text="${COPYRIGHT}" th:remove="tag"></div>
</footer>

<script>
    function initNav() {
        Base.ajax({
            "url": "/common/navs",
            "success": function (data) {
                var data = data.data || [];
                var _nav = $("#nav");
                for (var i = 0; i < data.length; i++) {
                    var d = data[i];
                    var funcId = d.funcId;
                    var funcName = d.funcName;
                    var funcUrl = d.funcUrl || 'javascript:void();';
                    var subs = d.subs || [];
                    if (subs.length > 0) {
                        var arr = [];
                        arr.push('<li class="dropdown">');
                        arr.push('<a href="' + funcUrl + '" class="dropdown-toggle" data-toggle="dropdown">' + funcName + '<b class="caret"></b></a>');
                        arr.push('<ul class="dropdown-menu">');
                        for (var j = 0; j < subs.length; j++) {
                            var sub = subs[j];
                            var subFuncId = sub.funcId;
                            var subFuncName = sub.funcName;
                            var subFuncUrl = sub.funcUrl || 'javascript:void();';
                            var target = "";
                            if (subFuncUrl.indexOf("/manage") != -1 || subFuncUrl.indexOf("/screen") != -1) {
                                target = "_blank";
                            }
                            arr.push('<li><a href="' + subFuncUrl + '" target="' + target + '">' + subFuncName + '</a></li>');
                        }
                        arr.push('</ul>');
                        arr.push('');
                        arr.push('');

                        arr = arr.join("");
                        _nav.prepend(arr);
                    } else {
                        var target = "";
                        if (funcUrl.indexOf("/manage") != -1 || funcUrl.indexOf("/screen") != -1) {
                            target = "_blank";
                        }
                        var str = '<li><a href="' + funcUrl + '" target="' + target + '">' + funcName + '</a></li>';
                        _nav.prepend(str);
                    }
                }
            }
        });
    }

    initNav();
</script>

</body>
</html>